import axios from 'axios'
import { store } from '../redux/store.js'
import { CHANGELOADING } from '../redux/constant.js'

axios.defaults.baseURL = 'http://localhost:5000'

axios.interceptors.request.use(function (config) {
	store.dispatch({
		type: CHANGELOADING,
		data: true
	})
	return config
})

axios.interceptors.response.use(function (response) {
	store.dispatch({
		type: CHANGELOADING,
		data: false
	})
	return response
}, function (error) {
	store.dispatch({
		type: CHANGELOADING,
		data: false
	})
	return Promise.reject(error)
})